package com.spica.spicaschool.ui.circle

import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.fragment.app.FragmentPagerAdapter
import androidx.navigation.Navigation
import com.google.android.material.transition.Hold
import com.kongzue.dialogx.dialogs.MessageDialog
import com.kongzue.dialogx.util.TextInfo
import com.spica.spicaschool.R
import com.spica.spicaschool.base.BaseFragment
import com.spica.spicaschool.databinding.FragmentCircleBinding
import com.spica.spicaschool.ui.main.MainFragmentDirections

/**
 * 圈子
 */
class CircleFragment : BaseFragment<FragmentCircleBinding>() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        exitTransition = Hold()
    }


    private fun initView() {
        viewBinding.viewpager.adapter =
            CircleFragmentAdapter(
                childFragmentManager,
                FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
            )
        viewBinding.viewpager.offscreenPageLimit = 3
        viewBinding.tablayout.setupWithViewPager(viewBinding.viewpager)
        val navigationController =
            Navigation.findNavController(requireActivity(), R.id.fragment_container_view)
        val messageDialog =
            MessageDialog("Spica 校园", "管理您的账号信息", "管理账号信息", "取消", "退出登录")
                .setButtonOrientation(LinearLayout.VERTICAL)

        messageDialog.okTextInfo = TextInfo().setFontColor(
            Color.parseColor("#EB5545")
        )

        viewBinding.btnMenu.setOnClickListener {
            navigationController.navigate(MainFragmentDirections.actionHomeToSetting())
        }
        viewBinding.ivAvatar.setOnClickListener {
            messageDialog.show()
        }
    }

    override fun setupViewBinding(
        inflater: LayoutInflater,
        container: ViewGroup?
    ): FragmentCircleBinding {
        return FragmentCircleBinding.inflate(inflater, container, false)
    }

    override fun init() {
        initView()
    }
}
